﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StackExchange.Redis;
using vabp;
using Xunit;
using Xunit.Sdk;

namespace Vabp.Infrastructure.Redis.Test
{
    public class RedisServiceTest:VabpTestBase<VabpInfrastructureRedisModule>
    {
        private IRedisService redisService;

        public RedisServiceTest()
        {
            this.redisService = GetService<IRedisService>();
        }

        [Theory]
        [InlineData()]
        public void GetDatabase_Test(RedisDataBaseType dbType = RedisDataBaseType.User)
        {

        }

        [Theory]
        [InlineData()]
        public string[] GetKeys_Test(RedisDataBaseType dbType = RedisDataBaseType.User)
        {
            return RedisHelper.GetServer().Keys(database: (int)dbType).Select(k => k.ToString()).ToArray();
        }

        public bool IsExsit_Test(string key, RedisDataBaseType dbIndex = RedisDataBaseType.User)
        {
            return RedisHelper.GetDatabase((int)RedisDataBaseType.User).KeyExists(key);
        }

        public string Remove_Test(string key, RedisDataBaseType dbType = RedisDataBaseType.User)
        {
//            var database = RedisHelper.GetDatabase((int)dbType);
//            var data = database.StringGet(key);
//
//            database.KeyDelete(key);
//            return data;

            string data = redisService.Remove("mykey");

            Assert.Equal(data, "33333");


        }

        [Fact]
        public void SetData_Test()
        {
            var data = redisService.SetData("mykey", "2222");
            Assert.NotNull(data);

            var data2 = redisService.SetData("mykey", data: "33333");
            Assert.Equal("2222", data2);
        }
    }
}
